$(function () {
    $('#captcha-img').click(function (event) {
       var self = $(this);
       var src = self.attr('src');
       var newsrc = zlparam.setParam(src,'xx',Math.random());
       self.attr('src',newsrc);
    });
});

$(function () {
    $('#email_captcha').click(function (event) {
        var  email = $("input[name='email']").val();
        if(!email){
            zlalert.alertInfoToast("请输入邮箱");
            return;
        }
        zlajax.get({
            'url':'/email_captcha/',
            'data': {
                'email': email
            },
            'success': function (data) {
                if(data['code'] == 200){
                    zlalert.alertSuccessToast('邮件发送成功！请注意查收！');
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail': function (error) {
                zlalert.alertNetworkError();
            }
        })
    });
});
$(function () {
    $('#submit-btn').click(function (event) {
        event.preventDefault();
        var email_input = $("input[name='email']");
        var email_captcha_input = $("input[name='email_captcha']");
        var username_input = $("input[name='username']");
        var password1_input = $("input[name='password1']");
        var password2_input = $("input[name='password2']");
        var graph_captcha_input = $("input[name='graph_captcha']");



        var username = username_input.val();
        var password1 = password1_input.val();
        var password2 = password2_input.val();
        var graph_captcha = graph_captcha_input.val();
        var email = email_input.val();
        var email_captcha = email_captcha_input.val();


        zlajax.post({
            'url':'/signup/',
            'data':{
                'username':username,
                'email':email,
                'email_captcha':email_captcha,
                'password1':password1,
                'password2':password2,
                'graph_captcha':graph_captcha
            },
            'success':function (data) {
                if (data['code']==200){
                    var return_to = $('#return-to-span').text();
                    if(return_to){
                        window.location = return_to;
                    }else{
                        window.location='/'
                    }
                }else{
                    zlalert.alertInfo(data['message']);
                }
            },
            'fail':function (data) {
             zlalert.alertNetworkError();
            }
        });
    });
});